import com.alibaba.fastjson.JSONObject;
import com.saybiu.domain.Picture;
import com.saybiu.domain.Post;
import com.saybiu.domain.PostMeta;
import com.saybiu.domain.User;
import com.saybiu.service.PostService;
import com.saybiu.utils.Utils;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: liming
 * @Date: 2021/4/18 18:06
 */
public class MyTest02 {

    /**
     * 测试图片缓存
     */
    @Test
    public void testPictureUrl(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<String> list = new ArrayList<>();
        list.add("liming.jpg");
        list.add("wnagwei.jpg");
        list.add("wnagfei.jpg");
        //List<Picture> list1 = postService.addPicture(18, list, "http://42.123.198.52:8080//bbs/file/image/userId");

    }


    /**
     * 测试用户发帖
     */
    @Test
    public void testAddUserSendPost(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        Post post = new Post();
        post.setUserId(16);
        post.setPostTitle("hello world");
        post.setPostTime(Utils.toDate(new Date()));
        post.setPostTypeName("表白墙");
        post.setUserNickname("奥特曼");


        PostMeta postMeta = new PostMeta();
        postMeta.setPostLatestUpdateTime(post.getPostTime());
        postMeta.setPostContent("hello world JavaEE");
        postMeta.setUserProfilePictureUrl("D://liming.jpg");


        //测试-- 前端传回的所有图片id数组
       // Integer[] picture = {102,103,104};
        //发送帖子没有图片
        //list = null;
        postService.addUserSendPost(post,postMeta,null);
    }


    /**
     * 用户删除帖子
     */
    @Test
    public void deleteUserPostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        postService.deleteUserPost(19,50);
    }

    /**
     *测试阅读帖子
     */
    @Test
    public void readPostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        postService.readPost(60);
    }

    /**
     * 测试用户给帖子点赞
     */
    @Test
    public void likePostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        postService.likePost(16,64,"http://biubiuer.com/lihuangying.app.apk");
    }

    /**
     * 测试用户给帖子点赞
     */
    @Test
    public void cancelLikePostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        postService.cancelLikePost(16,64);
    }

    /**
     * 测试用户收藏帖子
     */
    @Test
    public void collectionPostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        postService.collectionPost(16,64,"http://biubiuer.com/lihuangying.app.apk");
    }

    /**
     * 测试删除收藏帖子
     */
    @Test
    public void deleteUserSupportPostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        postService.deleteUserSupportPost(16,64);
    }

    /**
     * 测试用户查询所发的帖子
     */
    @Test
    public void queryUserPostTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryUserPost(19);
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }

    /**
     * 测试用户查询帖子内容
     */
    @Test
    public void queryUserPostMetaTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        PostMeta postMeta = postService.queryUserPostMeta(60);
        System.out.println("123"+postMeta);
    }

    /**
     * 测试根据帖子类型和阅读量查询
     */
    @Test
    public void queryPostsByTypeAndReadNumTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryPostsByTypeAndReadNum("表白墙");
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }

    /**
     * 测试根据帖子类型和点赞量查询
     */
    @Test
    public void queryPostByTypeAndLikeNumTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryPostByTypeAndLikeNum("表白墙");
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }

    /**
     * 测试根据帖子类型和收藏量查询
     */
    @Test
    public void queryPostByTypeAndCollectionNumTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryPostByTypeAndCollectionNum("表白墙");
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }

    /**
     * 根据阅读量查询帖子
     */
    @Test
    public void queryPostByReadNumTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryPostByReadNum();
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }

    /**
     * 根据点赞量查询帖子
     */
    @Test
    public void queryPostByLikeNumTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryPostByLikeNum();
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }
    /**
     * 根据收藏量查询帖子
     */
    @Test
    public void queryPostByCollectionNumTest(){
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/ApplicationContext.xml");
        PostService postService = (PostService) applicationContext.getBean("postServiceImpl");
        List<Post> list = postService.queryPostByCollectionNum();
        for (Post p:list) {
            System.out.println("123"+p);
        }
    }

    /**
     * 造数据:  json串
     */
    @Test
    public void test1111()
    {
        Picture picture =new Picture();
        picture.setPictureName("poo.jpg");
        picture.setUserId(17);
        Picture picture2 =new Picture();
        picture2.setPictureName("logo.jpg");
        picture.setUserId(17);
        Picture picture3 =new Picture();
        picture3.setPictureName("women.jpg");
        picture3.setUserId(17);

        List<Picture> users=new ArrayList<>();
        users.add(picture);
        users.add(picture2);
        users.add(picture3);
        System.out.println(JSONObject.toJSONString(users));
    }

    /**
     * 八位随机数
     */
    @Test
    public void test333(){
        System.out.println(Utils.creatRandom());
    }
}
